<?php
include_once("CONNEXION.php");
include_once("MySqlClass.php");
include_once("SQLExtJsInteract.php");



if (!((isset($_GET['MODEL'])) || (isset($_GET['ACTION'])))){
    echo 'MODEL et ACTION obligatiore ';
}



 $table='';
 $fields= array(); 	//attention l'ordre des champs doit être identique à ExtJS
 $primaryKey="id";

// varlorise les  variable du model adéquates 
switch($_GET['MODEL']){ 
	
		case 'app':
			$table ='app';
			array_push($fields, "id", "language", "type", "name", "status", "about_us", "title", "text", "store_url_apple", "store_url_google", "store_url_windows", "store_url_blackberry", "user_id");
		break;
		
                
		case 'apptrip':
			$table ='app_trip';
			array_push($fields, "id", "app_id", "trip_id", "list_order", "user_id");
		break;
            
                
		case 'tripspot':
			$table ='trip_spot';
			array_push($fields, "id", "trip_id", "spot_id", "list_order", "user_id");
		break;
            
		
		case 'spot':
			$table ='spot';
			array_push($fields, "id", "id_text", "name", "type", "phone", "adress_text", "gps_x", "gps_y", "status", "user_id");
		break;
		
		
		case 'spotdescription':
			$table ='spot_description';
			array_push($fields, "id", "spot_id", "type","language", "title", "text");
		break;
		
		case 'trip':
			$table ='trip';
			array_push($fields, "id", "name", "duration", "type", "status", "user_id");
		break;
		
		case 'tripdescription':
			$table ='trip_description';
			array_push($fields, "id", "trip_id", "language", "title", "text");
		break;
		
		
		case 'user':
			$table ='user';
			array_push($fields, "id", "type", "status", "email", "pwd", "name", "activity", "phone", "web_site_url", "adress_text", "country", "city", "zip_code");
		break;
		

		default:
			 echo 'erreur aucun model défine côté serveur ne correspond à '.$_GET['MODEL'];
		break;

}
 
$model = new SQLExtJsInteract($table, $fields, $primaryKey);



//filtre json renvoyé par EXTjs4
 $filterJson ='';
if(isset($_GET['filter'])){
	$filterJson = $_GET['filter'];
}


// covention : "root:data" dans ExtJS
//données automatiquements envoyées par ExtJS4 au format json
 $dataJson='';
if(isset($_POST['data'])){
	$dataJson = $_POST['data'];
}


	
//ACTION possible : LST ; ADD ; ADDALL ; UPD ; DEL
echo $model->doAction($_GET['ACTION'], $filterJson, $dataJson);


?>